package 比较器排序Comparator;

import java.util.Comparator;
import java.util.TreeSet;

public class Test {
    public static void main(String[] args) {
        TreeSet<Student>ts=new TreeSet<Student>(new Comparator<Student>() {
            @Override
            public int compare(Student s1, Student s2) {
            int num=s2.getSum()-s1.getSum();//通过成绩的总分进行比较，进行降序排序；
               int num2=num==0?s1.getChinese()-s2.getChinese():num;//如果总分一样，通过语文成绩的比较进行升序排序；
               int num3=num2==0?s1.getName().compareTo(s2.getName()):num2;//如果所有成绩都一样，那就通过姓名的比较进行排序
               return num3;
            }
        });
        Student s1=new Student("石昊卿",100,100);
        Student s2=new Student("张鹏" ,80,95);
        Student s3=new Student("吴云天",60,60);
        Student s4=new Student("黄芪",70,80);
        Student s5=new Student("胡啸天",80,90);
        Student s6=new Student("张泽康",66,66);
        ts.add(s1);
        ts.add(s2);
        ts.add(s3);
        ts.add(s4);
        ts.add(s5);
        ts.add(s6);
        for (Student s:ts){
            System.out.println(s.getName()+","+s.getChinese()+","
            +s.getMath());
        }



    }
}
